import * as THREE from 'three'
//位置
var SetObjectPosFromPosArray = function (object, posArray) {
  if (object != undefined && posArray != undefined && posArray.length == 3) {
    let pos = new THREE.Vector3()
    pos.fromArray(posArray)
    object.position.copy(pos)
  }
}
//欧拉角
var SetObjectRotationFromEulerAngleArray = function (object, eulerAngleArray) {
  if (object != undefined && eulerAngleArray != undefined && eulerAngleArray.length == 3) {
    let rotation = new THREE.Vector3()
    rotation.fromArray(eulerAngleArray)
    rotation.multiplyScalar(Math.PI / 180)

    object.rotation.x = rotation.x
    object.rotation.y = rotation.y
    object.rotation.z = rotation.z
  }
}
//缩放
var SetObjectScaleFromScaleArray = function (object, scaleArray) {
  if (object != undefined && scaleArray != undefined && scaleArray.length == 3) {
    let scale = new THREE.Vector3()
    scale.fromArray(scaleArray)
    object.scale.copy(scale)
  }
}

//整体从位置、欧拉角、缩放设置到物体
var SetObject3DParamFromJsonEle = function (object, jsonEle) {
  SetObjectPosFromPosArray(object, jsonEle.position)
  SetObjectRotationFromEulerAngleArray(object, jsonEle.eulerAngle)
  SetObjectScaleFromScaleArray(object, jsonEle.scale)
}

export {
  SetObjectPosFromPosArray,
  SetObjectScaleFromScaleArray,
  SetObjectRotationFromEulerAngleArray,
  SetObject3DParamFromJsonEle
}
